
var UserSQL={
  user:{
    add:'insert into admin(username,userpas,usertel) values  (?,?,?);',
    checklogin:'SELECT * FROM admin WHERE username = ?;',
    updataMsg:'update admin set usertel= ?,userage = ?,usersex = ?,userIntrod = ? where username = ?',
  },
  datames:{
    selectbasefood:'SELECT * FROM basefood',
    selectfoodbbs:'SELECT * FROM foodbbs',
    selectfoodbbschild:'SELECT * FROM foodbbs LEFT JOIN bbsrecom on foodbbs.articlid = bbsrecom.articlid where topic = ?',
    bbscommentcount:'SELECT * FROM bbsrecom',
    addbbscomment:'insert into bbsrecom(recomid,recomctx,articlid,recomtime,recomuser) values  (?,?,?,?,?);',
    addbbsimage:'insert into bbsimage(imagepath,oldname,newname) values  (?,?,?);',
    selectimage:'SELECT * FROM bbsimage where oldname = ?',
    uploadimg:'update bbsimage set newpath = ? where oldname = ?',
    addarticle:'insert into foodbbs(topic,context,user,admirnum,articlid,publictime,imgpath) values  (?,?,?,?,?,?,?);',
    deletbbscomment:'delete from bbsrecom where recomuser = ? and recomctx = ?',
    selectshop:'SELECT * FROM shoprecom',
    selectuserbyid: (id) => { return `SELECT * FROM user WHERE id=${id}` },
    selectshopbyid: (id) => { return `SELECT * FROM shoprecom WHERE id=${id}` },
    setshoplike: (shopId, userId, bLike, aOldUserId, aOldShopId) =>{
      function del(arr, id){
        arr.splice($.inArray(id, arr), 1);
      }
      if(bLike){ // 点赞
        return [
          `UPDATE shoprecom SET ${aOldUserId.push(userId)} WHERE id=${shopId}`,
          `UPDATE user SET ${aOldShopId.push(shopId)} WHERE id=${userId}`
        ]
      }
      else{ // 取消赞
        return [
          `UPDATE shoprecom SET ${del(aOldUserId, userId)} WHERE id=${shopId}`,
          `UPDATE user SET ${del(aOldShopId, shopId)} WHERE id=${userId}`
        ]
      }
    },
    addMsg: (userId, shopId, msg) => {
      return `INSERT INTO msgs ( userId, shopId, msg ) VALUES (${userId}, ${shopId}, ${msg} )`
    },
    deleteMsg: (msgId) => {
      return `DELETE FROM msgs WHERE id=${msgId}`
    },
    selectcook:'SELECT * FROM cookbook',
  },
  todayfood:{
    selectfoodMsg:'SELECT * FROM todayfood WHERE name = ?'
  }
}
module.exports=UserSQL;
